package org.jivesoftware.smackx.provider;

import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.commands.AdHocCommand.Action;
import org.jivesoftware.smackx.commands.AdHocCommand.SpecificErrorCondition;
import org.jivesoftware.smackx.commands.AdHocCommand.Status;
import org.jivesoftware.smackx.commands.AdHocCommandNote;
import org.jivesoftware.smackx.commands.AdHocCommandNote.Type;
import org.jivesoftware.smackx.packet.AdHocCommandData;
import org.jivesoftware.smackx.packet.AdHocCommandData.SpecificError;
import org.jivesoftware.smackx.packet.DataForm;
import org.xmlpull.v1.XmlPullParser;

public class AdHocCommandDataProvider
  implements IQProvider
{
  public IQ parseIQ(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    AdHocCommand.Action localAction;
    int i = 0;
    AdHocCommandData localAdHocCommandData = new AdHocCommandData();
    DataFormProvider localDataFormProvider = new DataFormProvider();
    localAdHocCommandData.setSessionID(paramXmlPullParser.getAttributeValue("", "sessionid"));
    localAdHocCommandData.setNode(paramXmlPullParser.getAttributeValue("", "node"));
    String str1 = paramXmlPullParser.getAttributeValue("", "status");
    if (AdHocCommand.Status.executing.toString().equalsIgnoreCase(str1))
    {
      localAdHocCommandData.setStatus(AdHocCommand.Status.executing);
      String str2 = paramXmlPullParser.getAttributeValue("", "action");
      if (str2 != null)
      {
        localAction = AdHocCommand.Action.valueOf(str2);
        if ((localAction != null) && (!(localAction.equals(AdHocCommand.Action.unknown))))
          break label181;
        localAdHocCommandData.setAction(AdHocCommand.Action.unknown);
      }
    }
    while (true)
    {
      label181: label190: int j;
      label263: label455: 
      do
        while (true)
        {
          do
            while (true)
            {
              while (true)
              {
                String str3;
                String str4;
                while (true)
                {
                  while (true)
                  {
                    while (true)
                    {
                      while (true)
                      {
                        String str6;
                        do
                        {
                          while (true)
                          {
                            while (true)
                            {
                              do
                                while (true)
                                {
                                  if (i == 0)
                                    break label190;
                                  return localAdHocCommandData;
                                  if (!(AdHocCommand.Status.completed.toString().equalsIgnoreCase(str1)))
                                    break;
                                  localAdHocCommandData.setStatus(AdHocCommand.Status.completed);
                                }
                              while (!(AdHocCommand.Status.canceled.toString().equalsIgnoreCase(str1)));
                              localAdHocCommandData.setStatus(AdHocCommand.Status.canceled);
                            }
                            localAdHocCommandData.setAction(localAction);
                          }
                          j = paramXmlPullParser.next();
                          str3 = paramXmlPullParser.getName();
                          str4 = paramXmlPullParser.getNamespace();
                          if (j != 2)
                            break label455;
                          if (!(paramXmlPullParser.getName().equals("actions")))
                            break label263;
                          str6 = paramXmlPullParser.getAttributeValue("", "execute");
                        }
                        while (str6 == null);
                        localAdHocCommandData.setExecuteAction(AdHocCommand.Action.valueOf(str6));
                      }
                      if (!(paramXmlPullParser.getName().equals("next")))
                        break;
                      localAdHocCommandData.addAction(AdHocCommand.Action.next);
                    }
                    if (!(paramXmlPullParser.getName().equals("complete")))
                      break;
                    localAdHocCommandData.addAction(AdHocCommand.Action.complete);
                  }
                  if (!(paramXmlPullParser.getName().equals("prev")))
                    break;
                  localAdHocCommandData.addAction(AdHocCommand.Action.prev);
                }
                if ((!(str3.equals("x"))) || (!(str4.equals("jabber:x:data"))))
                  break;
                localAdHocCommandData.setForm((DataForm)localDataFormProvider.parseExtension(paramXmlPullParser));
              }
              if (!(paramXmlPullParser.getName().equals("note")))
                break;
              AdHocCommandNote.Type localType = AdHocCommandNote.Type.valueOf(paramXmlPullParser.getAttributeValue("", "type"));
              String str5 = paramXmlPullParser.nextText();
              AdHocCommandNote localAdHocCommandNote = new AdHocCommandNote(localType, str5);
              localAdHocCommandData.addNote(localAdHocCommandNote);
            }
          while (!(paramXmlPullParser.getName().equals("error")));
          localAdHocCommandData.setError(PacketParserUtils.parseError(paramXmlPullParser));
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("command"))));
      i = 1;
    }
  }

  public static class BadActionError
  implements PacketExtensionProvider
  {
    public PacketExtension parseExtension(XmlPullParser paramXmlPullParser)
      throws Exception
    {
      return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badAction);
    }
  }

  public static class BadLocaleError
  implements PacketExtensionProvider
  {
    public PacketExtension parseExtension(XmlPullParser paramXmlPullParser)
      throws Exception
    {
      return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badLocale);
    }
  }

  public static class BadPayloadError
  implements PacketExtensionProvider
  {
    public PacketExtension parseExtension(XmlPullParser paramXmlPullParser)
      throws Exception
    {
      return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badPayload);
    }
  }

  public static class BadSessionIDError
  implements PacketExtensionProvider
  {
    public PacketExtension parseExtension(XmlPullParser paramXmlPullParser)
      throws Exception
    {
      return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.badSessionid);
    }
  }

  public static class MalformedActionError
  implements PacketExtensionProvider
  {
    public PacketExtension parseExtension(XmlPullParser paramXmlPullParser)
      throws Exception
    {
      return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.malformedAction);
    }
  }

  public static class SessionExpiredError
  implements PacketExtensionProvider
  {
    public PacketExtension parseExtension(XmlPullParser paramXmlPullParser)
      throws Exception
    {
      return new AdHocCommandData.SpecificError(AdHocCommand.SpecificErrorCondition.sessionExpired);
    }
  }
}